package com.esint.kafka.roles;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @description: 消费者类
 * @author: 谷明
 * @createDate: 2021/8/14 15:25
 */
@Component
@Slf4j
public class Consumer {
    @KafkaListener(topics = {"boot_test"})
    public void listen(ConsumerRecord<?, ?> record) {
        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
        if (kafkaMessage.isPresent()) {
            Object message = kafkaMessage.get();
            log.info("-----------------Consumer Says: record =" + record);
            log.info("------------------Consumer Says: message =" + message);
        }
    }
}
